/*
**  宝贝相关操作
*/
WHOOPSFEED.baobei = (function(){

	return {

		/*
		**	系统初始化
		*/
		init : function(){
            //推荐宝贝 弹出窗 start**********************
            var dialog_recommend_options = {
                triggerId:'#_recommend_baobei',
                temp:RecommendBaobeiDialogTemp,
                tempData:{'id':'#_dialog_recommend_baobei'},
                removeId:'#_close_recommend_baobei',
                completeEvent:function(){
                    $('#_recommend_info').html(RecommendBaobeiUrlTemp());
                    $('#_dialog_recommend_baobei div.newkeep div.tab ul li').live('click',function(){
                        $(this).siblings('li')
                            .removeClass('active')
                            .end()
                            .addClass('active');
                        var switch_type = $(this).find('span').attr('class');

                        switch (switch_type) {
                            case 'icon-link':
                                $('#_recommend_info').html(RecommendBaobeiUrlTemp());
                                break;
                            case 'icon-import':
                                $('#_recommend_info').html(RecommendBaobeiAddLikeTemp());
                                break;
                            case 'icon-upload':
                                $('#_recommend_info').html(RecommendBaobeiShareTemp());
                                break;
                        }
                    });
                }
            };

            WHOOPSFEED.base.show_remove_temp(dialog_recommend_options);
            //推荐宝贝 弹出窗 end**********************

            WHOOPSFEED.baobei.submit_get_baobei_info();//获取宝贝信息
            WHOOPSFEED.baobei.back_get_baobei_info();//返回获取宝贝信息
		},

        //获取宝贝信息
        submit_get_baobei_info : function(){
            $('#_submit_get_baobei_info').live('click',function(){
                var url;
                url = $(this).parents('dd').find('input[name=url]').val();
                 $.ajax({
                    type: 'POST',
                    url: 'ajax/baobei/aj_get_baobei_info.php?t=' + new Date().getTime(),
                    data: {"url":url},
                    dataType: 'json',
                    beforeSend: function(){
                        $('#_http_status').html('<img src="i/popup/pop-loading.gif" alt="请稍后" style="vertical-align:middle">&nbsp;&nbsp;<font style="font-size: 12px;color: green">请求数据中，请稍后！</font>').show();
                    },
                    TIMEOUT: '10000',
                    success: function (msg) {
                        if (msg.retCode == 1090) {
                            var img_list = msg.baobei_info.img_urls.split('|');
                            var baobei_title = msg.baobei_info.title;
                            var baobei_info_options = {
                                thumb:img_list[0].replace('40x40','310x310'),
                                thumb_list:img_list,
                                shop_title:msg.baobei_info.shop_title,
                                realy_baobei_title:baobei_title,
                                baobei_title:baobei_title.length > 30 ? baobei_title.substring(0,30)+'...' : baobei_title,
                                baobei_price:msg.baobei_info.price,
                                baobei_tags:msg.baobei_info.tags,
                                url:msg.baobei_info.url,
                                flag:msg.baobei_info.flag,
                                domain:msg.baobei_info.domain
                            };
                            $('#_recommend_info').html(RecommendBaobeiInfoShowTemp(baobei_info_options));
                            WHOOPSFEED.baobei.add_baobei_info(msg);//添加宝贝信息

                        } else if (msg.retCode == 1091) {
                            $('#_http_status').html('<font style="font-size: 12px;color: red">网络异常，请稍后在试！</font>').fadeOut(2000);
                        } else {
                            $('#_http_status').html('<font style="font-size: 12px;color: red">你已经分享过这个宝贝啦…</font>');
                        }
                    }
                })
            });


        },
        add_baobei_info : function(msg){
            $('#_submit_add_baobei_info').live('click',function(){
                $.ajax({
                    type:'POST',
                    url:'ajax/baobei/aj_get_baobei_info.php?t=' + new Date().getTime(),
                    data:{"url":'http://item.taobao.com/item.htm?spm=a2106.m893.1000384.d139.3OFGHL&id=17766271413&scm=1029.newlist-0.bts3.50031712&ppath='},
                    dataType:'json',
                    beforeSend:function () {
                        $('#_http_status').html('<img src="i/popup/pop-loading.gif" alt="请稍后" style="vertical-align:middle">&nbsp;&nbsp;<font style="font-size: 12px;color: green">请求数据中，请稍后！</font>').show();
                    },
                    TIMEOUT:'10000',
                    success:function (msg) {
                        if (msg.retCode == 1090) {
                            var baobei_status_options = {
                                status:msg.status
                            };
                            $('#_recommend_info').html(RecommendBaobeiInfoStatusTemp(baobei_status_options));
                        } else if (msg.retCode == 1091) {
                            $('#_http_status').html('<font style="font-size: 12px;color: red">网络异常，请稍后在试！</font>').fadeOut(2000);
                        } else {
                            $('#_http_status').html('<font style="font-size: 12px;color: red">你已经分享过这个宝贝啦…</font>');
                        }
                    }
                })

                $("div[id^='_dialog_como_']").remove();
            });
            //宝贝图片选择效果
            $('#_dialog_recommend_baobei div.thumb-list').find('img').live('click', function () {
                $(this).toggleClass("selected");
            });

            $('#_dialog_recommend_baobei div.thumb-list').find('img').live('mouseover', function () {
                $(this).parents('div.tabForm').find('div.thumb img').attr('src', $(this).attr('src').replace('40x40', '310x310'));
            });
        },

        back_get_baobei_info : function(){
            $('#_dialog_recommend_baobei').find('#_back_recommend').live('click',function(){
                $('#_recommend_info').html(RecommendBaobeiUrlTemp());
            });
        }
    }
})();
